<?php
//你要回复的内容，如要换行请用\n，
//如要用图片请按照这个格式 #(pic,2b8806e93901213f3c8b371655e736d12d2e95dc,442,614) 表情是这个格式 滑稽
$content = "帖子在哪里？我这要回复了哈";
//你的bduss
$bduss = "pVN1hUeUdMbGRqSVFRS2Q4QkV2bE1YRXN4bUt5c1l4QVVRNWwwWTNQQXhNc0ZvRVFBQUFBJCQAAAAAAAAAAAEAAAC8h16Cz-DW3dXys8fR9Mnnx~gAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADGlmWgxpZloa2";
$tid = "9938544112"; //你要回复贴子的tid
header("content-Type: text/html; charset=Utf-8");
function curl_post($pda, $url)
{
    $header = array("Content-Type: application/x-www-form-urlencoded");
    $data = implode("&", $pda) . "&sign=" . md5(implode("", $pda) . "tiebaclient!!!");
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
    curl_setopt($ch, CURLOPT_TIMEOUT, 30);
    $re = json_decode(curl_exec($ch));
    curl_close($ch);
    return $re;
}
function rand_int($l)
{ //生成指定位数的随机数
    $int = null;
    for ($e = 0; $e < $l; $e++) {
        $int .= mt_rand(0, 9);
    }
    return $int;
}
function getPage()
{
    global $bduss, $tid;
    $pd = array(
        "BDUSS=" . $bduss,
        "_client_id=wappc_136" . rand_int(10) . "_" . rand_int(3),
        "_client_type=" . mt_rand(1, 4),
        "_client_version=5.0.0",
        "_phone_imei=" . md5(rand_int(16)),
        "back=0",
        "kz=" . $tid,
        "net_type=3",
        "pn=1",
        "rn=2",
        "with_floor=1",
    );
    $gd = curl_post($pd, 'http://c.tieba.baidu.com/c/f/pb/page');
    if ($gd->error_code != 0) exit('发生错误：' . $gd->error_msg . '<br>');
    $tbs = $gd->anti->tbs;
    $fid = $gd->forum->id;
    $kw = $gd->forum->name;
    $title = $gd->thread->title;
    return replyPost($kw, $tbs, $fid, $title);
}
function replyPost($kw, $tbs, $fid, $title)
{
    global $bduss, $tid, $content;
    $pd = array(
        "BDUSS=" . $bduss,
        "_client_id=wappc_136" . rand_int(10) . "_" . rand_int(3),
        // "_client_type=" . mt_rand(1, 4), //设备标识，1-iPhone，2-Android，3-Windows Phone，4-Windows 8
        "_client_type=4",
        "_client_version=5.0.0",
        "_phone_imei=" . md5(rand_int(16)),
        'anonymous=0',
        'content=' . $content,
        'fid=' . $fid,
        //'is_ad=0',
        "kw=" . $kw,
        "net_type=3",
        'tbs=' . $tbs,
        'tid=' . $tid,
        'title='
    );
    $gd = curl_post($pd, 'http://c.tieba.baidu.com/c/c/post/add');
    if ($gd->error_code != 0) exit($kw . '吧｜' . $title . '｜发生错误：' . $gd->error_msg . '<br>');
    echo $kw . '吧｜' . $title . '｜回复成功<br>';
}
getPage();
